/**************************************************************************
	File		: tpa5050.c
	Author		: 
	Date		: 2018-8-18
***************************************************************************/
	
/**************************************************************************
    								include
***************************************************************************/
#include "i2c.h"
#include "tpa5050.h"
/**************************************************************************
    								macro
***************************************************************************/

/**************************************************************************
    								typedef
***************************************************************************/
	
/**************************************************************************
    								variables
***************************************************************************/
	
/**************************************************************************
    								functions
***************************************************************************/
void TPA_Init(uint8_t slaveAddr)
{
	uint8_t value;

	value = 0x00;			/* both active , I2S */
	I2C_Write(I2C2, slaveAddr, CONTROL, &value, 1);
}

void TPA_SetDelay(uint8_t slaveAddr, uint16_t delay, uint8_t channel)
{
	uint8_t value = 0x01;
	uint8_t delayValue[2] = {0};

	delayValue[0] = delay>>8;
	delayValue[1] = delay&0xff;

	I2C_Write(I2C2, slaveAddr, channel, delayValue, 2);
	I2C_Write(I2C2, slaveAddr, COMPLETE_UPDATE, &value, 1);
}

uint16_t TPA_GetDelay(uint8_t channel)
{
	uint16_t value = 0;
	uint8_t delayValue[2] = {0};

	I2C_Read(I2C2, TPA_5050_Address, channel, delayValue, 2);
	value = (delayValue[0]<<8) + delayValue[1];
	return value;
}

